$(document).ready(function() { 

    // Override default error message
    jQuery.validator.messages.required = "";
    
    // Override generation of error label
    jQuery("#newsletterform").validate({
        rules: {
            email: {
                required: true,
                email: true
            }
        },
        submitHandler: function(form) {

            jQuery('#newsletterform_submit').attr('disabled','disabled');
            
            var form = jQuery("#newsletterform");
            var form_data = form.serialize();

            jQuery.ajax({
                url: form.attr('action'),
                dataType: 'json',
                type: "POST",
                data: form_data,
                success: function (data, textStatus, xhr) {

                    if(data.action){
                        alert(data.msg);
                    }else{
                        alert(data.msg);                            
                    }
                    jQuery('#newsletterform_submit').removeAttr('disabled');
                },
                error: function (xhr, textStatus, errorThrown) {
                    alert('Error ocured...\n Server not found.');
                    jQuery('#newsletterform_submit').removeAttr('disabled');
                }
            });

            return false;

        },
        errorPlacement: function(error, element){}
        


    });

    jQuery('#contact_info_submit').removeAttr('disabled');
    jQuery('#submit_newsletter').live('click', function(){
        jQuery("#newsletterform").submit();
    });

});